import java.util.Arrays;
import java.util.Random;

/**
 * @author CHENTAIWEN
 * @create 2022/11/16 20:43
 */
public class saolei {

    public static void main(String[] args) {
        int[][] it = putBomb(20, 20, 20);
        System.out.println(Arrays.deepToString(it));
    }

    public static int[][] putBomb(int h, int w, int count) {
        Random r = new Random();
        // bomb location array
        int[] bombLocs = new int[count];
        // 先放count个到里面
        for (int i = 0; i < count; i++) {
            bombLocs[i] = i;
        }
        // 再从count+1到最后，生成随机数，如果随机数小于count，就替换掉
        for (int i = count; i < h * w; i++) {
            int j = r.nextInt(i + 1);
            if (j < count) {
                bombLocs[j] = i;
            }
        }
        int[][] res = new int[h][w];
        for (int i = 0; i < bombLocs.length; i++) {
            int x = bombLocs[i] / w;
            int y = bombLocs[i] % w;
            res[x][y] = 1;
        }
        return res;
    }
}
